package lpl.com.xyd.test.manage.controller;

import com.alibaba.fastjson.JSONObject;
import lpl.com.xyd.test.manage.common.response.HttpResponse;
import lpl.com.xyd.test.manage.common.utils.ContentType;
import lpl.com.xyd.test.manage.facade.WorkPlanFacade;
import lpl.com.xyd.test.manage.form.WorkPlanAddForm;
import lpl.com.xyd.test.manage.form.WorkPlanQueryMyForm;
import lpl.com.xyd.test.manage.info.WorkPlanInfo;
import lpl.com.xyd.test.manage.order.WorkPlanAddOrder;
import lpl.com.xyd.test.manage.order.WorkPlanMyOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/work/plan")
public class WorkPlanController {

    private final static Logger LOGGER = LoggerFactory.getLogger(WorkPlanController.class);

    @Autowired
    private WorkPlanFacade workPlanFacade;

    @RequestMapping(value = "/add",method = RequestMethod.POST,produces = {ContentType.APPLICATION_JSON_UTF_8,
            ContentType.TEXT_XML_UTF_8 })
    public HttpResponse<WorkPlanInfo> add(@RequestBody WorkPlanAddForm form){
        LOGGER.info("新增工作周报, form:{}", JSONObject.toJSONString(form));
        WorkPlanAddOrder order = new WorkPlanAddOrder();
        BeanUtils.copyProperties(form,order);
        return workPlanFacade.addWorkPlan(order);
    }

    @RequestMapping(value = "/queryMy",method = RequestMethod.POST,produces = {ContentType.APPLICATION_JSON_UTF_8,
            ContentType.TEXT_XML_UTF_8 })
    public HttpResponse<List<WorkPlanInfo>> queryMy(@RequestBody WorkPlanQueryMyForm form){
        LOGGER.info("我的周报, form:{}", JSONObject.toJSONString(form));
        WorkPlanMyOrder order = new WorkPlanMyOrder();
        BeanUtils.copyProperties(form,order);
        return workPlanFacade.queryMy(order);
    }
}
